const { body, query, param } = require('express-validator');
const cityData = require('../config/city_data');

// 城市名称验证
const validateCity = () => 
    body('city').custom(value => {
        const valid = cityData.provinces.some(province => 
            province.cities.some(city => city.name === value)
        );
        if (!valid) throw new Error('无效的城市名称');
        return true;
    });

// 时间格式验证 (HH:mm)
const validateTimeFormat = (field) => 
    body(field).matches(/^([01]\d|2[0-3]):([0-5]\d)$/).withMessage('时间格式应为HH:mm');

// 防XSS过滤
const xssFilter = () =>
    body('*').escape();

module.exports = {
    validateCity,
    validateTimeFormat,
    xssFilter
};